import { useState, useEffect } from "react"
import { getChannelsApi } from "@/apis/article";

const useChannel = () => {
  // 获取频道列表
  const [channelsList,setChannelsList] = useState([])
  useEffect(() => {
    // 封装函数，在函数体内调用接口
    const getChannelsList = async () => {
      const res = await getChannelsApi()
      setChannelsList(res.data.channels)
    }
    getChannelsList()
  },[])
  // return 出需要使用的数据
  return {
    channelsList
  }
}

export default useChannel